package cn.tedu.spring.example;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class TestUser {
    public static void main(String[] args) {
        /**
         * 方式1:new
         */
        User1 user =new User1();
        user.userRun();

        /**
         * 方式2:通过反射
         */
        try {
            Class xx=Class.forName("cn.tedu.spring.example.User1");
        User1 user1=(User1) xx.newInstance();
        user1.userRun();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        /**
         * 方式3:通过spring框架创建对象
         */
        ApplicationContext context=new
                AnnotationConfigApplicationContext("cn.tedu.spring.example");
        User1 user3= context.getBean(User1.class);
        user3.userRun();

    }
}
